#include "uart9bit.h"


namespace igslib
{
    RS232_9bit::RS232_9bit()
    {
       
    }
    
    int RS232_9bit::Send(short* addr,int length)
    {
        //printf("rs232 send  %x \n",length);
        int n=0; 
        //printf("rs232_9bit send  %d \n",length);
        n = RS232_SendBuf(port,(unsigned char*)addr,length);
        //printf("rs232_9bit n = %d  \n",n);
        return n;
    }
    int RS232_9bit::Receive(short* addr,int length)
    {
    	
    	//return RS232_PollComport(port,tmp,length);
    	tmp = (unsigned char *)malloc(sizeof(unsigned char)*length);
        
        
        int n = RS232_PollComport(port,tmp,length);
        // for(int a=0; a< n;a++)
        // {
            
        //     printf("tmp %d  : %x \n",a,tmp[a]);
        // }
        // printf("rs232_9bit n : %d \n",n);
        if( n >0)
        {
            for(int i =0; i<n/2; i++)
            {
                addr[i] = tmp[i*2] | tmp[i*2+1] <<8;
                //printf("9bit read addr %d : %02x  \n",i,addr[i]);
            }   
        }
        return n/2;
        
    }
};
